<?php
/**
 * Created by JetBrains PhpStorm.
 * User: porterzhang
 * Date: 13-3-19 下午3:34
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}

include_once 'forum.php';
class cloud_api {
    function common() {
        global $_G;
        //是否缺少参数
        if (empty($_GET['udid']) || empty($_GET['caption'])) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }

        //上传文件
        $_FILES['Filedata']['name'] = addslashes(diconv(urldecode($_FILES['Filedata']['name']), 'UTF-8'));
        $_FILES['Filedata']['type'] = $_GET['filetype'];
        //初始化上传的文件信息
        $file = plugin_cloud::update_init($_FILES['Filedata'], 'article');
        //保存到指定的文件夹中
        plugin_cloud::saveUpload($file);

        //将图片缩放
        $filename = $file['target'];
        $dw = intval(400);
        $imginfo = @getimagesize($filename);
        $dh = intval($imginfo[1]);


        $thumbfile = "article/".$file['attachdir']. plugin_cloud::get_target_filename('article')  . $dw .'.'. $file['extension'];
        error_log("thumbfile:".$thumbfile );
        require_once libfile('class/image');
        $img = new image;
        //将图片缩略，如果成功则返回图片，否则返回流文件
        if($img->Thumb($filename, $thumbfile, $dw, $dh)){
            $file['attachment'] =str_replace("article/","",$thumbfile);
        }

        //将图片插入到数据库中，并返回id
        $insert = array(
            'udid' => $_GET['udid'],
            'caption' => $_GET['caption'],
            'isaudit' => 0,
            'image_url' => $file['attachment'],
            'lasttime' => TIMESTAMP,
        );
        $id = C::t('#cloud#cloud_photo_wall')->insert($insert);
        if(!empty($id)){
            $variable = array(
                'messagestr' => lang('plugin/cloud', '110002'),
            );
        }else{
            $variable = array(
                'code'=>110003,
                'messagestr' => lang('plugin/cloud', '110003'),
            );
        }

        cloud_core::result(cloud_core::variable($variable));
    }

    function output() { }


}
?>

